package leftMain;

import java.io.PrintWriter;

import org.dlsu.mt.parser.FStructure;
import org.dlsu.mt.parser.TRANSFER.TransferDictionary;
import org.dlsu.mt.parser.dictionary.Global;


public class LEFTTranslator
{
	org.dlsu.mt.parser.dictionary.Dictionary language2Dictionary = new org.dlsu.mt.parser.dictionary.Dictionary("Language2");
	org.dlsu.mt.parser.dictionary.Dictionary language1Dictionary = new org.dlsu.mt.parser.dictionary.Dictionary("Language1");
	TransferDictionary transferDictionary  = new TransferDictionary();
	AnalysisModule analysis;
	TransferModule transfer;
	GenerationModule gen;
	Global glob = new Global();
	PrintWriter pw;
		
	public LEFTTranslator(PrintWriter pw) throws Exception
	{
		this.pw = pw;
		analysis = new AnalysisModule();
		gen = new GenerationModule();
		glob.setPrintWriter(pw);
		transfer = new TransferModule(language1Dictionary, language2Dictionary, glob);					
	}
	
	public void setLanguage1Dictionary(org.dlsu.mt.parser.dictionary.Dictionary dict){
		language1Dictionary = dict;
	}
	
	public void setLanguage2Dictionary(org.dlsu.mt.parser.dictionary.Dictionary dict){
		language2Dictionary = dict;
	}
	
	public String translate1To2(String text) throws Exception
	{
							
		analysis.reload("/home/pckid/LEFT/language1.txt", language1Dictionary);
		gen.loadGrammar("/home/pckid/LEFT/language2.txt");			
		
				
		pw.println("Text to be translated: " + text.toUpperCase());
		pw.println("Direction of translation is: language1 to language2");
		pw.println("Starting translation...");
				
		
		FStructure f = analysis.analyze(text+" $");
		String temp = null;
		
		//System.out.println("ENTERING THE TRANSFER PHASE");
		
							
		if(f != null)
		{
			transfer.setDirectionOfTranslation('1');
			
			f = transfer.translate(f);
			//System.out.println("abot hanggang dito");
		}
		
		//
				
		temp = gen.generateString(f);
		pw.println("Output sentence: " + temp.toUpperCase());
		pw.println("Translation finished...");
		pw.println(" ");
		pw.println(" ");
		pw.println(" ");
				
		return temp;
	}
	
	public String translate2To1(String text) throws Exception
	{
		analysis.reload("/home/pckid/LEFT/language2.txt", language2Dictionary);
		gen.loadGrammar("/home/pckid/LEFT/language1.txt");
		
		pw.println("Text to be translated: " + text.toUpperCase());
		pw.println("Direction of translation is: language2 to language1");
		pw.println("Starting translation...");
		
		FStructure f = analysis.analyze(text+" $");
		String temp = null;
		
		if(f != null)
		{
			transfer.setDirectionOfTranslation('2');
			f = transfer.translate(f);
		}
				
		temp = gen.generateString(f);
		
		pw.println("Output sentence: " + temp.toUpperCase());
		pw.println("Translation finished...");
		pw.println(" ");
		pw.println(" ");
		pw.println(" ");
			
		return temp;
	}
	
	
}
